package com.bhatni.taskmanager.schedule;

import java.util.Calendar;
import java.util.Date;

public class PeriodicSchedule extends ScheduleBase /*    */ {

    long delay_ms = 0L;

    public void setRps(float rps) {
        if (rps > 1000.0F) {
            this.delay_ms = 1L;
        } else if (rps == 0.0F) {
            this.delay_ms = -1L;
        } else {
            this.delay_ms = ((int) (1000.0D / rps));
        }
    }

    public float getRps() {
        if (this.delay_ms < 0L) {
            return 0.0F;
        }
        if (this.delay_ms == 0L) {
            return 1000.0F;
        }
        return (float) (1000.0D / this.delay_ms);
    }

    @Override
    public Date getNextSchedule() {
        if (this.delay_ms < 0L) {
            return null;
        }
        if (this.lastScheduleTime == null) {
            Calendar lastSchedule = Calendar.getInstance();
            this.lastScheduleTime = lastSchedule.getTime();
        } else {
            this.lastScheduleTime.setTime(this.lastScheduleTime.getTime() + this.delay_ms);
        }
        return this.lastScheduleTime;
    }
}